﻿using B.S.DataBase.MyProject.Domain.RBAC;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.CommandHandler.Menus;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.RoleCommandHandler
{
    public class QueryMenuIdByRoleCommandHandler : IRequestHandler<QueryMenuIdByRoleCommand, APIResult<List<RoleMenu>>>
    {
        private readonly IBaseRepository<RoleMenu> rolemenuRep;

        public QueryMenuIdByRoleCommandHandler(IBaseRepository<RoleMenu> rolemenuRep)
        {
            this.rolemenuRep = rolemenuRep;
        }

        public async Task<APIResult<List<RoleMenu>>> Handle(QueryMenuIdByRoleCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<RoleMenu>> result = new APIResult<List<RoleMenu>>();

            var model = rolemenuRep.GetAll().Result.Where(x => x.RoleId == request.RoleId);

            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.data = model.ToList();
            return await Task.FromResult(result);
        }
    }
}
